package Sequence;

public class Test0112 {
}

class Solution0112_1 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) return false;
        if(root.left==null&&root.right==null){
            return targetSum-root.val==0;
        }
        return hasPathSum(root.left, targetSum-root.val)||hasPathSum(root.right, targetSum-root.val);
    }

}

class Solution0112_2 {
    public boolean hasPathSum(TreeNode root, int targetSum) {
        if (root == null) return false;
        targetSum-=root.val;
        if (root.left==null&&root.right==null) return targetSum == 0;
        return hasPathSum(root.left, targetSum) || hasPathSum(root.right, targetSum);
    }
}